package ar.edu.itba.it.poo.dd.frontend

import java.awt.Color
import java.awt.Image

import ar.edu.itba.it.poo.dd.backend.Bonus
import ar.edu.itba.it.poo.dd.backend.Dragon
import ar.edu.itba.it.poo.dd.backend.EmptyCell
import ar.edu.itba.it.poo.dd.backend.Enemy
import ar.edu.itba.it.poo.dd.backend.Golem
import ar.edu.itba.it.poo.dd.backend.HealthBonus
import ar.edu.itba.it.poo.dd.backend.Snake
import ar.edu.itba.it.poo.dd.backend.StrengthBonus
import ar.edu.itba.it.poo.dd.backend.Tile
import ar.edu.itba.it.poo.dd.backend.Wall
import ar.edu.itba.it.poo.dd.frontend.gui.ImageUtils.drawString
import ar.edu.itba.it.poo.dd.frontend.gui.ImageUtils.loadImage
import ar.edu.itba.it.poo.dd.frontend.gui.ImageUtils.overlap

object Images {
  lazy val player = loadImage("images/player.png")
  lazy val dragon = loadImage("images/dragon.png");
  lazy val snake = loadImage("images/snake.png");
  lazy val golem = loadImage("images/golem.png");
  lazy val blood = loadImage("images/blood.png")
  lazy val healthBonus = loadImage("images/healthBonus.png");
  lazy val strengthBonus = loadImage("images/strengthBonus.png");
  lazy val wall = loadImage("images/wall.png");
  lazy val background = loadImage("images/background.png")

  def forTile(tile: Tile): Option[Image] = {
    def forEnemy(enemy: Enemy) = if (enemy.isAlive) {
      Some(drawString(enemy.enemyType match {
        case Dragon => dragon
        case Golem => golem
        case Snake => snake
      }, enemy.level.toString, Color.WHITE))
    } else Some(blood)

    def forBonus(bonus: Bonus) = if (!bonus.taken) {
      Some(drawString(bonus match {
        case b: HealthBonus => healthBonus
        case b: StrengthBonus => strengthBonus
      }, bonus.ammount.toString, Color.WHITE))
    } else None

    if (tile.visible) {
      val image = tile match {
        case t: Wall => Some(wall)
        case t: Enemy => forEnemy(t)
        case t: Bonus => forBonus(t)
        case t: EmptyCell => Some(background)
      }

      Some(if (image.isDefined) overlap(background, image.get) else background)
    } else {
      None
    }
  }
}